import React, { Component } from "react";
// Provider 提供数据
// Consumer 消费数据
const MsgContext = React.createContext();

class Son extends Component {
  static contextType = MsgContext;
  render() {
    return (
      <div>
        <h2>Son</h2>
        {/* context 是在对象挂载了接收value的值 */}
        {this.context}
      </div>
    );
  }
}

// Son.contextType = MsgContext;

class Parent extends Component {
  render() {
    return (
      <div>
        <h2>parent</h2>
        <Son></Son>
      </div>
    );
  }
}

export default class App extends Component {
  state = {
    msg: "app组件的数据",
  };
  render() {
    return (
      <div>
        <h1>app</h1>
        {/* value是固定的属性用于设置数据 */}
        <MsgContext.Provider value={this.state.msg}>
          <Parent></Parent>
        </MsgContext.Provider>
      </div>
    );
  }
}
